package lumis.portal.group.databaseviewmembership;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import lumis.util.query.QueryFieldTypes;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;

/**
 * Fields that are read from the database view for obtaining data used
 * for selecting the members of a group. 
 *
 * @version $Revision: 10458 $ $Date: 2009-06-02 15:49:09 -0300 (Tue, 02 Jun 2009) $
 * @since 4.2.1
 */
@Entity
@Table(name="lum_GroupDbVwField")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@GenericGenerator(name="portal-guid", strategy="lumis.portal.dao.hibernate.GuidGenerator")
public class DatabaseViewField
{
	@Id @GeneratedValue(generator="portal-guid")
	private String id;
	private String columnName;
	private String dataType;
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="groupTypeConfigId")
	private DatabaseViewGroupTypeConfig groupTypeConfig;
	
	/**
	 * Returns the identifier of this field.
	 * @return the identifier.
	 * @since 4.2.1
	 */
	public String getId()
	{
		return id;
	}
	
	/**
	 * Returns the column name for this field.
	 * @return the column name.
	 * @since 4.2.1
	 */
	public String getColumnName()
	{
		return columnName;
	}
	
	/**
	 * Sets the column name for this field.
	 * @param columnName the column name.
	 * @since 4.2.1
	 */
	public void setColumnName(String columnName)
	{
		this.columnName = columnName;
	}
	
	/**
	 * Returns the data type of this field.
	 * @return one of the constants in {@link QueryFieldTypes}.
	 * @since 4.2.1
	 */
	public String getDataType()
	{
		return dataType;
	}
	
	/**
	 * Sets the data type of this field.
	 * @param dataType one of the constants in {@link QueryFieldTypes}.
	 * @since 4.2.1
	 */
	public void setDataType(String dataType)
	{
		this.dataType = dataType;
	}
	
	/**
	 * Returns the group type configuration this field definition belongs to.
	 * @return the group type configuration.
	 * @since 4.2.1
	 */
	public DatabaseViewGroupTypeConfig getGroupTypeConfig()
	{
		return groupTypeConfig;
	}
	
	/**
	 * Sets the group type configuration this field definition belongs to.
	 * @param groupTypeConfig the group type configuration.
	 * @since 4.2.1
	 */
	public void setGroupTypeConfig(DatabaseViewGroupTypeConfig groupTypeConfig)
	{
		this.groupTypeConfig = groupTypeConfig;
	}
}